package com.smallA.utils;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.springframework.stereotype.Component;

@Component
public class EmailUtils {
    public static boolean sendEmail(String emailaddress, String msg) {
        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName("smtp.qq.com");
            email.setCharset("utf-8");
            email.addTo(emailaddress);
            //这个就是收邮件的地址了
            email.setFrom("1990609801@qq.com", "考试系统通知");
            //此处填邮箱地址和用户名,用户名可以任意填写
            email.setSubject("考试系统通知");
            //此处填写邮件名，邮件名可任意填写
            email.setMsg(msg);
            //此处填写邮件内容
            email.setAuthentication("1990609801@qq.com", "oomnqgofvntidjjf");
            //此处填写邮箱地址和客户端授权码
            email.setSSLOnConnect(true);
            email.setSmtpPort(465);
            //开始SSL发送通道并配置465端口发送
            email.send();
            //发送邮件
            return true;
        } catch (EmailException e) {
            return false;
        }

    }
}
